﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

namespace pcsse.MasterPages
{
    public partial class WebForm7 : System.Web.UI.Page
    {
        string text_id;
        static string cate_id;
        news_data nd;
        static string file_path;
        private void Set_Value(ref news_data newsdata)
        {
            this.Title = newsdata.news_title;
            Label1.Text = newsdata.news_title;
            Label2.Text = newsdata.news_content;
            Label3.Text = newsdata.date;
            cate_id = newsdata.category_id.ToString();
            LinkButton2.Text = db_news.getDBhandle().GetCategoryById(newsdata.category_id);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            text_id = Request.QueryString["id"];
            nd = db_news.getDBhandle().GetNewsByID(text_id);
            if (Session["Priority"] != null)
            {
                if (Convert.ToInt32(Session["Priority"]) < nd.news_permission) Response.Redirect("..\\");
            }
            Set_Value(ref nd);
            if (nd.am_id == -1)
            {
                LinkButton1.Visible = false;
            }
            else
            {
                LinkButton1.Enabled = true;
                LinkButton1.Text = "附件:" + nd.am_name;
                file_path = Server.MapPath("~/") + nd.am_path;
            }
            //Label1.Text = sqlstr;
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("news_explore.aspx");
        }
        public void start_dl(string fpath)
        {

            Response.ContentType = "application/x-zip-compressed";
            Response.AddHeader("Content-Disposition", "attachment;filename=" + nd.am_name);
            Response.TransmitFile(fpath);
        }
        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            start_dl(file_path);
        }

        protected void LinkButton2_Click(object sender, EventArgs e)
        {
            string urlstr = "news_explore.aspx?cateid=" + cate_id;
            Response.Redirect(urlstr);
        }
    }
}
